﻿@using BlazorComponent;
@using Microsoft.AspNetCore.Components.Web;
@using Microsoft.JSInterop;
@using Masa.Blazor;
@using ThingsGateway.Core.Extension
@using ThingsGateway.Core.Extension.Json
@using ThingsGateway.Foundation
@namespace ThingsGateway.Demo
@inherits AdapterDebugBase

<MCard Class="ma-2">
    <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Start">

        <MCol Md="5">
            <MTabs @bind-Value="tab" Class="">
                <MTab Value=1>   @AppService.I18n.T("Common Functions")    </MTab>
                <MTab Value=2>    @AppService.I18n.T("Special Functions")    </MTab>
            </MTabs>

            <MTabsItems Value="tab">
                <MTabItem Value="1">
                    @if (ShowDefaultReadWriteContent)
                    {
                        <MContainer>
                            <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                                <MTooltip Right Context="tip">
                                     <ActivatorContent>
                                         <MTextarea Class="pa-1" Style="max-width:200px" Dense Outlined HideDetails="@("auto")"
                                                    Label=@AppService.I18n.T("Register Address") @attributes="@tip.Attrs" @bind-Value=@RegisterAddress />
                                     </ActivatorContent>
                                     <ChildContent>
                                         <span style="white-space: pre-wrap;">@Plc?.GetAddressDescription()</span>
                                    </ChildContent>
                                </MTooltip>


                                <MCol Align="AlignTypes.Center">
                                    <MTextField Class="pa-1" Style="max-width:200px" Dense Outlined HideDetails="@("auto")"
                                                 @bind-Value=@ArrayLength Label=@AppService.I18n.T("Array Length") />

                                     <MSelect Class="pa-1" Style="max-width:200px" Outlined
                                              @bind-Value="DataType" Label=@AppService.I18n.T("DataType")
                                              Items=@(typeof(DataTypeEnum).GetEnumList())
                                              MenuProps="@(props => { props.Auto = true; props.OffsetY = true; })"
                                              ItemText=@(u =>u.Description)
                                              ItemValue=@(u =>(DataTypeEnum)u.Value)
                                              HideDetails=@("auto") Height="30"
                                          Dense>
                                 </MSelect>

                                 <MButton Class="ma-1" Color="primary" OnClick="ReadAsync">
                                     @AppService.I18n.T("Read")
                                    </MButton>

                                </MCol>
                            </MRow>


                            <MRow Class="mt-8" Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                                <MTextarea Class="pa-1" Style="max-width:200px" Dense Outlined HideDetails="@("auto")"
                                            Label=@AppService.I18n.T("WriteValue") @bind-Value=@WriteValue />
                                 <MCol Align="AlignTypes.Center">
                                     <MButton Class="ma-1" Color="primary" OnClick="WriteAsync">
                                         @AppService.I18n.T("Write")
                                    </MButton>
                                </MCol>
                            </MRow>


                            <MRow Class="mt-8" Justify="JustifyTypes.Start" Align="AlignTypes.Center">

                                <MTooltip Right Context="tip">
                                     <ActivatorContent>
                                         <MTextarea Class="pa-1" Style="max-width:200px" @attributes="@tip.Attrs" Dense Outlined HideDetails="@("auto")"
                                                    Label=@AppService.I18n.T("Send Raw Data") @bind-Value=@SendValue />
                                     </ActivatorContent>
                                     <ChildContent>
                                         <span style="white-space: pre-wrap;">@AppService.I18n.T("HexString")</span>
                                    </ChildContent>
                                </MTooltip>

                                <MCol Align="AlignTypes.Center">
                                    <MButton Class="ma-1" Color="primary" OnClick="Send">
                                        @AppService.I18n.T("Send")
                                    </MButton>
                                </MCol>
                            </MRow>

                        </MContainer>

                    }
                    @if (ReadWriteContent != null)
                    {
                        @ReadWriteContent
                    }
                </MTabItem>

                <MTabItem Value="2">
                    @if (ShowDefaultOtherContent)
                    {
                        <MSubheader Style="max-height:24px" Class="font-weight-black text-subtitle-1">
                            @AppService.I18n.T("ReadPack")
                        </MSubheader>
                        <MContainer>

                            @foreach (var item in VariableRunTimes)
                            {
                                <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Center">
                                    <MTextarea AutoGrow Style="max-width:200px" RowHeight=20 Rows=4 Class="pa-1" Dense Outlined HideDetails="@("auto")"
                                                Label=@AppService.I18n.T("Register Address") @bind-Value=@item.RegisterAddress />
                                     <MCol Align="AlignTypes.Center">
                                         <MSelect Class="pa-1" Style="max-width:200px" Outlined
                                                  @bind-Value="item.DataType" Label=@AppService.I18n.T("DataType")
                                                  Items=@(typeof(DataTypeEnum).GetEnumList())
                                                  MenuProps="@(props => { props.Auto = true; props.OffsetY = true; })"
                                                  ItemText=@(u =>u.Description)
                                                  ItemValue=@(u =>(DataTypeEnum)u.Value)
                                                  HideDetails=@("auto") Height="30"
                                              Dense>
                                     </MSelect>

                                     <MTextField Class="pa-1" Outlined Style="max-width:200px" Dense HideDetails="@("auto")"
                                                     Label=@AppService.I18n.T("IntervalTime") @bind-Value=@item.IntervalTime></MTextField>
                                     </MCol>
                                     <MCol Align="AlignTypes.Start">
                                         <div>@AppService.I18n.T("RealTimeValue")</div>
                                        <div title=@(item.LastErrorMessage) class=@(item.IsOnline?"success--text":"warning--text")>@(item.Value?.ToJsonString())</div>
                                    </MCol>

                                </MRow>

                            }
                            <MRow Justify="JustifyTypes.Start" Align="AlignTypes.Start">
                                <MTextField Class="ma-1" Outlined Style="max-width:200px" Dense HideDetails="@("auto")"
                                             Label=@AppService.I18n.T("Max Pack Length") @bind-Value=@MaxPack></MTextField>
                                 <MButton Class="ma-1" Color="primary" OnClick="MulReadAsync">
                                     读取
                                 </MButton>
                             </MRow>
                         </MContainer>

                    }

                    @if (OtherContent != null)
                    {
                        @OtherContent
                    }






                </MTabItem>


            </MTabsItems>

        </MCol>

        <MCol Md="7">
            <ConsoleTxt Messages="Messages" Height=Height OnExportClick="OnExportClick"></ConsoleTxt>
        </MCol>

    </MRow>

</MCard>


 

